package logic

import (
	"B/shenzhou_srv/model/mysql"
	"context"

	"B/shenzhou_srv/internal/svc"
	"B/shenzhou_srv/shenzhou"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsListLogic {
	return &GoodsListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodsListLogic) GoodsList(in *shenzhou.GoodsListRequest) (*shenzhou.GoodsListResponse, error) {
	// todo: add your logic here and delete this line
	var g mysql.Goods
	list := g.List(in.Status)

	var user []*shenzhou.GoodsList
	for _, u2 := range list {
		user = append(user, &shenzhou.GoodsList{
			Id:     int64(u2.ID),
			Title:  u2.Title,
			Price:  float32(u2.Price),
			Cover:  u2.Cover,
			Stock:  int64(u2.Stock),
			Status: u2.Status,
			Type:   u2.Type,
		})
	}
	return &shenzhou.GoodsListResponse{List: user}, nil
}
